//
//  GYMapTopView1.m
//  StudyOC
//
//  Created by czera on 2020/11/8.
//

#import "GYMapTopView1.h"

@interface GYMapTopView1 ()
@property(nonatomic,strong)UIView *redView;
@property(nonatomic,strong)UIButton *switchBtn;
@property(nonatomic,assign)BOOL isSwitch;
@end

@implementation GYMapTopView1

-(instancetype)init{
    self = [super init];
    if (!self) return nil;
    
    // 自定义函数
    UILabel *titleLab = [[UILabel alloc] init];
    [self addSubview:titleLab];
    titleLab.backgroundColor = [UIColor yellowColor];
    titleLab.numberOfLines = 0;
    titleLab.text = @"课阿斯蒂芬就物品几节课";
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
    }];

    _redView = [[UIView alloc] init];
    _redView.backgroundColor = [UIColor redColor];
    [self addSubview:_redView];
    [_redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(titleLab.mas_right).offset(-100);
        make.top.equalTo(titleLab.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
    }];

    _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_switchBtn];
    [_switchBtn addTarget:self action:@selector(switchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    _switchBtn.backgroundColor = [UIColor blackColor];
    [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_redView.mas_top);
        make.right.equalTo(self.mas_right);
        make.height.width.mas_equalTo(32);
    }];

    _switchBtn.layer.borderColor = [UIColor redColor].CGColor;
    _switchBtn.layer.borderWidth = 1;

    UILabel *titleLab1 = [[UILabel alloc] init];
    [_redView addSubview:titleLab1];
    titleLab1.backgroundColor = [UIColor yellowColor];
    titleLab1.numberOfLines = 0;
    titleLab1.text = @"kkjsde";
    [titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_redView.mas_left).offset(10);
        make.top.equalTo(_redView.mas_top).offset(10);
        make.right.equalTo(_redView.mas_right).offset(-100);
    }];

    UIView *bottomView = [[UIView alloc] init];
    [self addSubview:bottomView];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(titleLab.mas_right);
        make.top.equalTo(_redView.mas_bottom).offset(10);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
        make.height.mas_equalTo(20);
    }];
    return self;
}


-(void)switchBtnAction:(id)sender{

    if (!self.isSwitch) {
        [UIView animateWithDuration:0.5 animations:^{

            self.switchBtn.imageView.transform = CGAffineTransformMakeRotation(M_PI);
            [self.redView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(100);
            }];
//            [self mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.height.mas_equalTo(self.frame.size.height+60);
//            }];
//            [self layoutIfNeeded];
            
            NSLog(@"====> 1 _topView1 frame %f  %f",self.frame.size.width,self.frame.size.height);
        }];
        self.isSwitch = YES;
    }
    else
    {
        [UIView animateWithDuration:0.5 animations:^{

            self.switchBtn.imageView.transform = CGAffineTransformIdentity;

            [self.redView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(40);
            }];
//            [self mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.height.mas_equalTo(self.frame.size.height-60);
//            }];
//        
//            [self layoutIfNeeded];
            
            NSLog(@"====> 1 _topView1 frame %f  %f",self.frame.size.width,self.frame.size.height);
        }];
        self.isSwitch = NO;
    }
}

@end
